package main

/* import "fmt"
import "unsafe" */

// _"fmt"表示忽略
import (
	"fmt"
	"strconv"
	"unsafe"
)

//int 类型数据在32位系统中占4个字节，在64位系统中占8个字节（uint同理）
//rune 等价于int32
//byte 与uint8等价
func main() {
	//整型 默认0
	var i int8 = 1 //int8 取值范围 -128-127 int8 占一个字节
	fmt.Println("i =",i)
	var num = 100
	//fmt.Printf：用于做格式化输出	%T:返回变量的数据类型	%c:返回变量的ASCII值
	fmt.Printf("num : %T, %c\n",num, num)
	var num2 int64 = 200
	//SizeOf()返回变量占用的字节数	
	fmt.Printf("num : %T , 占 %d 个字节\n", num2, unsafe.Sizeof(num2))

	//浮点型 默认0
	//尾数部分可能有丢失，造成精度损失 默认为float64
	var price float32 = 92.02
	fmt.Println("price =", price)
	var float1 float32 = -123.0000901
	var float2 float64 = -123.0000901	//开发中使用float64
	fmt.Println("float1 =", float1, "float2 =",float2)	
	//结果为float1 = -123.00009 float2 = -123.0000901  float1精度损失

	//字符类型 
	//使用byte保存在ASCII中的字符，其他的使用int数据类型保存
	var c1 byte = 'c'
    fmt.Printf("c1 的类型: %T, 值为%c\n", c1, c1)
	var c2 int = '中'
	fmt.Printf("c2 的类型: %T, 值为%c\n", c2, c2)

	//bool类型 占一个字节 默认false
	//不能使用1/0表示真假
	var b bool = true
	fmt.Println("b =", b)
	fmt.Printf("b = 占%d个字节\n", unsafe.Sizeof(b))	//1

	//字符串 ""
	//双引号:识别转义字符
	//反引号:以字符串的原生形式输出，包括换行和特殊字符，可以实现防止攻击，输出源代码
	var address string = "河南"
	fmt.Println("address =", address)
	var detailAddress string = address + "南阳"
	fmt.Println("detailAddress =", detailAddress)
	//使用"+"做字符串拼接时，需要将"+"留在上一行结尾
	var hello string = "hello " + "hello " + "hello " +
						"hello " + "hello " + "hello " +
						"hello " + "hello " + "hello "
	fmt.Println("hello =", hello)

	//数据类型的转换
	//大转小 溢出
	var source int32 = 99
	var target float32 = float32(source)
	fmt.Printf("target : %T %v\n", target, target)

	//转string
	//1.
	var targetS string 
	var source2 int = 999
	var source3 float64 = 112.000087
	var source4 bool = true
	var source5 byte = 'c'
	targetS = fmt.Sprintf("%d", source2)
	fmt.Printf("targetS : %T %q\n", targetS,targetS)
	targetS = fmt.Sprintf("%f", source3)
	fmt.Printf("targetS : %T %q\n", targetS,targetS)
	targetS = fmt.Sprintf("%t", source4)
	fmt.Printf("targetS : %T %q\n", targetS,targetS)
	targetS = fmt.Sprintf("%c", source5)
	fmt.Printf("targetS : %T %q\n\n", targetS,targetS)
	//2.
	var targetS2 string
	targetS2 = strconv.FormatInt(int64(source2), 10)
	fmt.Printf("targetS2 : %T %q\n", targetS2, targetS2)
	targetS2 = strconv.FormatFloat(source3, 'f', 10, 64)
	fmt.Printf("targetS2 : %T %q\n", targetS2, targetS2)
	targetS2 = strconv.FormatBool(source4)
	fmt.Printf("targetS2 : %T %q\n", targetS2, targetS2)
}